package com.androidsocketd.recycler;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.androidsocketd.R;
import com.androidsocketd.bean.MachineNumber;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yao on 2021/3/24.
 * Describe
 */

public class NormalRecyclerViewAdapter extends RecyclerView.Adapter<NormalRecyclerViewAdapter.NormalTextViewHolder> {
    private final LayoutInflater mLayoutInflater;
    private final Context mContext;
    private String[] mTitles;
    private List<MachineNumber> machineNumberList;

    private OnItemClickListener onItemClickListener;

    public OnItemClickListener getOnItemClickListener() {
        return onItemClickListener;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }


    public NormalRecyclerViewAdapter(Context context, List<MachineNumber> machineNumberList) {
        mContext = context;
        mLayoutInflater = LayoutInflater.from(context);
        this.machineNumberList = machineNumberList;
    }
    public void notifyChange(List<MachineNumber> machineNumberList){
        this.machineNumberList = machineNumberList;
        notifyDataSetChanged();
    }


    @Override
    public NormalTextViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new NormalTextViewHolder(mLayoutInflater.inflate(R.layout.item_show_message, parent, false));
    }

    @Override
    public void onBindViewHolder(NormalTextViewHolder holder, final int position) {
        holder.idShow.setText(machineNumberList.get(position).getId()+"");
        holder.showMessage.setText(machineNumberList.get(position).getMachineName());
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemClick(v,position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return machineNumberList.size();
    }

    public static class NormalTextViewHolder extends RecyclerView.ViewHolder {



        @BindView(R.id.idShow)
        TextView idShow;
        @BindView(R.id.showMessage)
        TextView showMessage;
        @BindView(R.id.delete)
        Button delete;

        NormalTextViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int positopn);
    }


}
